package com.td.module.equipment.controller.admin.waterpump;

import com.td.framework.common.pojo.CommonResult;
import com.td.framework.common.pojo.PageResult;
import com.td.module.equipment.controller.admin.info.vo.InfoPageReqVO;
import com.td.module.equipment.controller.admin.info.vo.InfoRespVO;
import com.td.module.equipment.controller.admin.info.vo.InfoUpdateReqVO;
import com.td.module.equipment.controller.admin.waterpump.vo.PumpPageReqVO;
import com.td.module.equipment.controller.admin.waterpump.vo.PumpRespVO;
import com.td.module.equipment.controller.admin.waterpump.vo.PumpUpdateReqVO;
import com.td.module.equipment.controller.admin.waterpump.vo.WaterPumpRespVO;
import com.td.module.equipment.convert.info.InfoConvert;
import com.td.module.equipment.convert.waterpump.PumpConvert;
import com.td.module.equipment.convert.waterpump.WaterPumpConvert;
import com.td.module.equipment.dal.dataobject.info.InfoDO;
import com.td.module.equipment.dal.dataobject.waterpump.PumpDO;
import com.td.module.equipment.framework.core.ZhyClient;
import com.td.module.equipment.service.waterpump.PumpService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.HashMap;
import java.util.List;

import static com.td.framework.common.pojo.CommonResult.success;

@Api(tags = "管理后台 - 水泵管理")
@RestController
@RequestMapping("/equipment/water-pump")
@Validated
public class WaterPumpController {

    @Resource
    ZhyClient zhyClient;

    @Resource
    PumpService pumpService;

    @GetMapping("/page")
    @ApiOperation("获得水泵信息列表分页")
    public CommonResult<List<WaterPumpRespVO>> getAcquisitionInfoList(@RequestParam("pageNo") int pageNo, @RequestParam("pageSize") int pageSize) {
        List<HashMap<String, Object>> listData = zhyClient.deviceList(pageNo, pageSize);
        return success(WaterPumpConvert.INSTANCE.convertList(listData));
    }

    @GetMapping("/temp-page")
    @ApiOperation("获得水泵信息列表分页")
    public CommonResult<PageResult<PumpRespVO>> getAcquisitionInfoPageTemp(@Valid PumpPageReqVO pageVO) {
        PageResult<PumpDO> pageResult = pumpService.getPumpPage(pageVO);
        return success(PumpConvert.INSTANCE.convertPage(pageResult));
    }

    @PutMapping("/temp-update")
    @ApiOperation("控制水泵开关")
    public CommonResult<Boolean> updateInfo(@Valid @RequestBody PumpUpdateReqVO updateReqVO) {
        pumpService.updatePump(updateReqVO);
        return success(true);
    }
}
